package ACM.shence;

/**
 * @Author wwk
 * @DATE 2022/8/26 20:02
 */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Node{

    int val;
    ArrayList<Node> children;

    Node(){

    }
    Node(int val){
        this.val = val;
        this.children = new ArrayList<Node>();
    }
}

public class second {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        while(n-->0){
            int from = sc.nextInt();
            int to = sc.nextInt();
            map.put(from,to);

        }
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
        int from = sc.nextInt();
        int to = sc.nextInt();
        while(map.get(from) !=  map.get(to)){
            from = map.get(from);
            to = map.get(to);
        }
        System.out.println(map.get(from));


    }

    private static Node lowestCommonAncestor(Node root, Node c1, Node c2){
        if(root == null || root==c1 || root == c2){
            return root;
        }
        for (Node child : root.children) {
            Node node = lowestCommonAncestor(child, c1, c2);
            if(node!=null){
                return node;
            }
        }
        return root;
    }


    private static void  main1(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //根节点总是1
        Node root = new Node(1);
        //用于记录这里的节点
        Map<Integer, Node> map = new HashMap<Integer, Node>();
        map.put(1,root);
        while(n-->0){
            int from = sc.nextInt();
            int to = sc.nextInt();
            Node fromNode;
            Node toNode;
            fromNode = map.containsKey(from) ? map.get(from) : new Node(from);
            toNode = map.containsKey(to) ? map.get(to) : new Node(to);
            toNode.children.add(fromNode);
            map.put(from,fromNode);
            map.put(to,toNode);
        }
        int city1 = sc.nextInt();  //出发城市1
        int city2 = sc.nextInt();  //出发城市1
        Node c1Node;
        Node c2Node;
        c1Node = map.containsKey(city1) ? map.get(city1) : new Node(city1);
        c2Node = map.containsKey(city2) ? map.get(city2) : new Node(city2);
        if(root.children.contains(c1Node) && root.children.contains(c2Node)){
            System.out.println(root.val);
        }else{
            //找到公共父节点即可
            Node node = lowestCommonAncestor(root, c1Node, c2Node);
            System.out.println(node.val);
        }

    }
}
